package logic

import (
	"context"
	"technician_srv/technician"

	"technician/internal/svc"
	"technician/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type TechnicianInsertLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTechnicianInsertLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TechnicianInsertLogic {
	return &TechnicianInsertLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TechnicianInsertLogic) TechnicianInsert(req *types.TechnicianInsertRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	insertTechnician, err := l.svcCtx.TechnicianSrv.InsertTechnician(l.ctx, &technician.InsertTechnicianRequest{
		Name:   req.Name,
		Cover:  req.Cover,
		Mobile: req.Mobile,
		Age:    req.Age,
		City:   req.City,
	})
	if err != nil {
		return &types.Response{
			Code:    200,
			Message: "添加技师失败",
			Data: map[string]interface{}{
				"insertTechnician": insertTechnician,
			},
		}, nil
	}

	return &types.Response{
		Code:    200,
		Message: "添加技师成功",
		Data: map[string]interface{}{
			"insertTechnician": insertTechnician,
		},
	}, nil
}
